package TCP_test1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class RecciveMassage {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10086);
        //等待连接
        Socket socket = ss.accept();

        //获取输入流
        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);

        //读取数据
        int b;
        /*
        read方法会从连接通道中读取数据
        但是需要有一个结束标记 循环才会停止
        否则会一直停留在read方法这里，等待读取下面数据
         */
        while((b=br.read())!=-1){
            System.out.print((char)b);
        }

        /*
        //获取输出流
        OutputStream os = socket.getOutputStream();
        //写入数据
        os.write("真的吗？".getBytes());
         */
        socket.close();
        ss.close();

    }
}
